package cn.edu.sbs.talent.shiro.mapper;

import cn.edu.sbs.talent.common.mapper.BaseMapper;
import cn.edu.sbs.talent.shiro.entity.Account;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 账户 Mapper
 *
 * @author ctidy
 * @since 2021/1/7
 */
public interface AccountMapper extends BaseMapper<Account> {

    /**
     * 按用户名查询用户
     * @param username 用户名
     * @return 账户
     */
    @Select("SELECT DISTINCT `a`.* FROM `t_account` AS `a` WHERE `username` = #{username} AND `deleted` = 0 ")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(
                    property = "roles", column = "id", javaType = List.class,
                    many = @Many(select = "cn.edu.sbs.talent.shiro.mapper.RoleMapper.selectBatchByAccountId")
            )
    })
    Account selectByUsername(String username);

    // TODO t_account 与 t_account_role 级联逻辑删除
}
